//
//  TimelineCollectionPresenter.m
//  MVC|MVP|MVVM
//
//  Created by Guo Rui on 2017/11/14.
//  Copyright © 2017年 GR Harry. All rights reserved.
//

#import "TimelineCollectionPresenter.h"
#import "Service.h"
#import "TimelineModel.h"
#import "TimelinePresenter.h"

@interface TimelineCollectionPresenter() 
@property (strong, nonatomic) NSMutableArray <TimelinePresenter *> *timelinePresenters;
@end

@implementation TimelineCollectionPresenter
#pragma mark - TimelineCollectionPresenterProtocol
- (void)loadData
{
    __weak typeof(self) _self = self;
    [Service.sharedInstance fetchTimelineWithCompletion:^(NSArray <TimelineModel *> *array) {
        for (TimelineModel *model in array) {
           TimelinePresenter *p = [[TimelinePresenter alloc] init];
            p.model = model;
            [_self.timelinePresenters addObject:p];
        }
        [_self.vc reloadData];
    }];
}

- (NSInteger)numberOfItems
{
    return self.timelinePresenters.count;
}

- (void)presenterCell:(MVP_TableViewCell *)cell atIndex:(NSInteger)index
{
    TimelinePresenter *p = [self.timelinePresenters objectAtIndex:index];
    p.view = cell;
}

#pragma mark - Getter
- (NSMutableArray *)timelinePresenters
{
    if (!_timelinePresenters) {
        _timelinePresenters = [NSMutableArray arrayWithCapacity:0];
    }
    return _timelinePresenters;
}
@end
